<script setup lang="ts">
import { useRouter } from 'vue-router'
defineProps<{
  title?: string
  rightText: string
}>()

const emits = defineEmits<{
  (e: 'clickRight'): void
}>()

const router = useRouter()
const onClickLeft = () => {
  if (history.state.back) {
    router.go(-1)
  } else {
    router.push('/')
  }
}
const onClickRight = () => {
  emits('clickRight')
}
</script>

<template>
  <van-nav-bar
    fixed
    :title="title"
    :right-text="rightText"
    left-arrow
    @click-left="onClickLeft"
    @click-right="onClickRight"
  />
</template>

<style scoped lang="scss">
:deep() {
  .van-nav-bar {
    &__arrow {
      font-size: 18px;
      color: var(--cp-text1);
    }
    &__text {
      font-size: 15px;
    }
  }
}
</style>
